#!/bin/sh

find_self() {
	SELF_DIR=`dirname $0`
}

usage() {
	echo "usage: $0 <termination file>"
	exit 1
}

#MAIN
find_self

if [ $# -lt 1 ]; then
	usage
fi

. $SELF_DIR/QEMU_OPTS

touch /tmp/$0-$$
cat $PID > /tmp/$0-$$ 2> /dev/null

P=`cat /tmp/$0-$$`
if [ "$PID" != "" ]; then

	ps -p $P > /dev/null 2> /dev/null
	while [ "$?" == "0" ] ; do
	    sleep 1
	    ps -p $P > /dev/null 2> /dev/null
	done

fi

sudo mount $TMP_DISK $MNTDIR
sudo cp -r $MNTDIR/mnt/share/* $SHARE
sudo chown -R flaviov:lsd $SHARE
sudo umount $MNTDIR
rm $TMP_DISK
